// 保存极速问诊下单过程中数据（逐步完善）
import { defineStore } from 'pinia';
import { ref } from 'vue';
import type { Consult, ConsultIllness } from '@/types/consult';

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // consult 对象
    const consult = ref<Consult>({});

    // 设置问诊类型
    const setType = (type: 1 | 2 | 3) => {
      consult.value.type = type;
    };
    // 设置医院（疾病类型）
    const setIllnessType = (illnessType: 0 | 1) => {
      consult.value.illnessType = illnessType;
    };
    // 设置诊室数据
    const setDept = (id: string) => {
      consult.value.depId = id;
    };
    // 设置病情描述
    const setIllness = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc;
      consult.value.illnessTime = illness.illnessTime;
      consult.value.consultFlag = illness.consultFlag;
      consult.value.pictures = illness.pictures;
    };
    // 设置患者id
    const setPatintId = (id: string) => {
      consult.value.patientId = id;
    };
    // 设置优惠券id
    const setCouponId = (id: string) => {
      consult.value.couponId = id;
    };

    // 清空consultStore
    const clear = () => {
      consult.value = {};
    };

    return {
      consult,
      setType,
      setIllnessType,
      setDept,
      setIllness,
      setPatintId,
      setCouponId,
      clear,
    };
  },
  { persist: true }
);
